<style type="text/css">
</style>
<template>
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
        <Form-item label="物资项名称" prop="title">
            <i-input v-model="formValidate.title" placeholder="请输入物资项名称"></i-input>
        </Form-item>
        <Form-item label="型号" prop="serial">
            <i-input v-model="formValidate.serial" placeholder="请输入型号"></i-input>
        </Form-item>
        <Form-item label="规格" prop="size">
            <i-input v-model="formValidate.size" placeholder="请输入规格"></i-input>
        </Form-item>
        <Form-item label="厂商" prop="vender">
            <i-input v-model="formValidate.vender" placeholder="请输入厂商"></i-input>
        </Form-item>
        <Form-item label="采购源" prop="byfrom">
            <i-input v-model="formValidate.byfrom" placeholder="请输入采购源"></i-input>
        </Form-item>
        <Form-item label="采购源联系人" prop="fromcontact">
            <i-input v-model="formValidate.fromcontact" placeholder="请输入采购源联系人"></i-input>
        </Form-item>
        <Form-item label="采购源联系电话" prop="fromphone">
            <i-input v-model="formValidate.fromphone" placeholder="请输入采购源联系电话"></i-input>
        </Form-item>
        <!--<Form-item label="分配的物资分类" prop="fortype">-->
            <!--<i-select v-model="formValidate.fortype" placeholder="请选择分配的物资分类">-->
                <!--<template v-for="(item,index) in fortypeArr">-->
                    <!--<i-option :value="item.Value">{{item.Value}}</i-option>-->
                <!--</template>-->
            <!--</i-select>-->
        <!--</Form-item>-->
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
            <i-button type="ghost" @click="jumpPage('','AmmunitionList')" style="margin-left: 8px">返回</i-button>
        </Form-item>
    </i-form>
</template>
<script>
    import apiUtil from '../../assets/utils/api_util';
    import baseUtil from '../../assets/utils/base-util';

    export default {
        data() {
            return {
                formValidate: {
                    //添加字段
                    title: '',
                    serial: '',
                    size: '',
                    vender: '',
                    byfrom: '',
                    fromcontact: '',
                    fromphone: '',
                    fortype: '弹药储备',
                },
                ruleValidate: {},
                fortypeArr: [],
            }
        },

        mounted: function () {
            // this.getForTypeData();
        },

        methods: {
            //跳转
            jumpPage: function (id, url) {
                //跳转
                let route = '';
                if (id.length > 0) {
                    route = {
                        path: url,
                        query: {
                            id: id
                        },
                    };
                } else {
                    route = {
                        path: url,
                    };
                }

                this.$router.push(route);
            },
            //添加
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.addData(model);
                })
            },
            // getForTypeData: function () {
            //     let that = this;
            //
            //     let params = '';
            //     this.$Loading.start();
            //
            //     apiUtil.get(that, apiUtil.urls.MaterialTypeList, params, function (res) {
            //         that.$Loading.finish();
            //
            //         that.fortypeArr = res.Msg;
            //     });
            // },
            addData: function (model) {
                let that = this;

                let params = that.$qs.stringify(model);
                this.$Loading.start();

                apiUtil.post(that, apiUtil.urls.AddMaterialItem, params, function (res) {
                    that.$Loading.finish();

                    that.$Modal.confirm({
                        title: '操作成功',
                        content: '请选择下一步操作',
                        okText: '继续添加',
                        cancelText: '返回列表',
                        onOk: () => {
                            that.$router.go(0);
                        },
                        onCancel: () => {
                            baseUtil.pageJump(that, '', 'MaterialItemList');
                        }
                    });
                });
            },

            uploadList() {
                let that = this;
                this.imageList = that.$refs.upload ? that.$refs.upload.fileList : [];
                console.log('this.imageList:', this.imageList);
                // return ;
            },

        }
    }
</script>
